﻿Imports System.Configuration
Imports SISSAT.BusinessLayer.DomainModels

Namespace Utilities
    Public Class SemesterHelper

        Public Shared Function GetCurrentSemester() As Semesters
            Dim firstSemesterStartMonth As Integer = _
                Convert.ToInt32(ConfigurationManager.AppSettings("FirstSemesterStartMonth"))
            Dim firstSemesterEndMonth As Integer = _
                Convert.ToInt32(ConfigurationManager.AppSettings("FirstSemesterEndMonth"))
            Dim summerSemesterStartMonth As Integer = _
                Convert.ToInt32(ConfigurationManager.AppSettings("SummerSemesterStartMonth"))
            Dim summerSemesterEndMonth As Integer = _
                Convert.ToInt32(ConfigurationManager.AppSettings("SummerSemesterEndMonth"))

            Dim semester As Semesters = Semesters.Second
            Dim month As Integer = DateTime.Now.Month
            If month >= firstSemesterStartMonth AndAlso month <= firstSemesterEndMonth Then
                semester = Semesters.First
            ElseIf month >= summerSemesterStartMonth AndAlso month <= summerSemesterEndMonth Then
                semester = Semesters.Summer
            End If

            Return semester
        End Function

        Public Shared Function GetCurrentSchoolYear() As Integer
            Dim schoolYear As Integer = DateTime.Now.Year
            Dim currentSemester As Semesters = SemesterHelper.GetCurrentSemester()

            If currentSemester = Semesters.Second OrElse currentSemester = Semesters.Summer Then
                schoolYear = DateTime.Now.AddYears(-1).Year
            End If

            Return schoolYear
        End Function

    End Class
End Namespace

